package cn.sc.allinpay.allfavour.business.payment;

import android.os.Bundle;
import android.support.v7.widget.AppCompatButton;
import android.support.v7.widget.AppCompatEditText;
import android.support.v7.widget.AppCompatTextView;
import android.text.Editable;
import android.text.InputFilter;
import android.text.TextWatcher;
import android.view.View;

import butterknife.BindView;
import butterknife.OnClick;
import cn.sc.allinpay.allfavour.R;
import cn.sc.allinpay.allfavour.base.activity.BaseActivity;
import cn.sc.allinpay.allfavour.base.widget.CashierInputFilter;


/**
 * activity 去支付
 * author：pany
 * on 2017/12/1 11:14
 */
public class PaymentActivity extends BaseActivity<PaymentContract.View, PaymentContract.Presenter>
        implements PaymentContract.View {

    @BindView(R.id.tvGuideName)
    AppCompatTextView tvGuideName;//导购名
    @BindView(R.id.tvPaidAmt)
    AppCompatTextView tvPaidAmt;//待支付金额
    @BindView(R.id.etCash)
    AppCompatEditText etCash;//现金
    @BindView(R.id.btnCash)
    AppCompatButton btnCash;//现金
    @BindView(R.id.tvBalAmt)
    AppCompatTextView tvBalAmt;//剩余金额
    @BindView(R.id.btnCard)
    AppCompatButton btnCard;//银行卡
    @BindView(R.id.btnScan)
    AppCompatButton btnScan;//扫码

    @Override
    protected int layoutId() {
        return R.layout.activity_payment;
    }

    @Override
    protected void layoutTitle(View top, AppCompatTextView left, AppCompatTextView title, AppCompatTextView right) {
        title.setText("支付");
    }

    @Override
    protected PaymentContract.Presenter bindPresenter() {
        return new PaymentPresenter();
    }

    @Override
    protected void layoutContent(Bundle savedInstanceState) {

    }

    @Override
    public void showGuideName(String data) {
        tvGuideName.setText(data);
    }

    @Override
    public void showPaidAmt(String data) {
        tvPaidAmt.setText(data);
    }

    @Override
    public void setCashMaxAmt(String maxAmt) {
        //设置输入的最大金额
        InputFilter[] filters = {new CashierInputFilter(maxAmt)};
        etCash.setFilters(filters);
        etCash.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                presenter.countBalAmt();
            }
        });
    }

    @Override
    public String getCashAmt() {
        return etCash.getText().toString().trim();
    }

    @Override
    public void showBalAmt(String data) {
        tvBalAmt.setText(data);
    }

    @Override
    public void btnCashClickable(boolean able) {
        if (able) {
            btnCash.setClickable(true);
            btnCash.setBackgroundResource(R.drawable.selector_btn_submit);
        } else {
            btnCash.setClickable(false);
            btnCash.setBackgroundResource(R.color.pressColor);
        }
    }

    @Override
    public void btnCardClickable(boolean able) {
        if (able) {
            btnCard.setClickable(true);
            btnCard.setBackgroundResource(R.drawable.selector_btn_submit);
        } else {
            btnCard.setClickable(false);
            btnCard.setBackgroundResource(R.color.pressColor);
        }
    }

    @Override
    public void btnScanClickable(boolean able) {
        if (able) {
            btnScan.setClickable(true);
            btnScan.setBackgroundResource(R.drawable.selector_btn_submit);
        } else {
            btnScan.setClickable(false);
            btnScan.setBackgroundResource(R.color.pressColor);
        }
    }

    @OnClick({R.id.btnCash, R.id.btnCard, R.id.btnScan})
    void btnClick(View view) {
        switch (view.getId()) {
            case R.id.btnCash:
                presenter.callCash();
                break;
            case R.id.btnCard:
                presenter.callSale();
                break;
            case R.id.btnScan:
                presenter.callScan();
                break;
        }
    }
}
